***************************************************************
//					~ Resetting Stata ~
***************************************************************

// Declare Stata Version
version 16

// Reset Stata Parameters
clear all
set maxvar 30000
set more off
clear matrix
clear mata
eststo clear
log close _all
timer clear
set seed 49740

***************************************************************
//					 ~ Path Directories ~
***************************************************************

// Base Directory
	// TODO: You need to change the base directory to where you saved the replication package.
global dir "C:/Users/username/replication_packet"     

// Folder Navigation
global dir_data		"$dir/data"
global dir_outputs	"$dir/outputs"

// Output Preference: only one at a time
global excel "off"
global latex "on"
	if "$excel" == "on" {
		global output "excel"
		global file "xls" 
	}
	if "$latex" == "on" {
		global output "tex"
		global file "tex"
	}
	

***************************************************************
//					 ~ Dependencies ~
***************************************************************

// These are the packages you will need to run this script
local package_list outreg2 distplot

// Flag in the beginning to download ado files needed to run
foreach package of local package_list {
	cap which `package'
	if _rc di "{red: This script needs -`package'-, please install first (try -ssc install `package'-)}"
	if _rc stop
}

***************************************************************
//   				Toggle Sections
***************************************************************		

global table_A1 	"on"
global table_A2 	"on"
global figure_A3 	"on"
global table_A3 	"on"
global table_A4		"on"
global table_A5		"on"  
global table_A6		"on"
global table_A7		"on"
global table_A8		"on"
global table_A9		"on"
global table_A10	"on"
global table_A11	"on"
global table_A12	"on"
global table_A13	"on"
global table_A14	"on"


***************************************************************
//					Table A.1
***************************************************************
if "$table_A1" == "on" {

use "${dir_data}/sd_hh_endline", clear

// List district by province
	by id_province: tab id_district

// Covid Cases by District
	tab id_district, sum(r3_cases_dlvl)

// Cases per 100,000 by District 
	tab id_district, sum(r3_pccases_dlvl)

// Population
	tab id_district, sum(pop2017_dlvl)
	
}


***************************************************************
//					Table A.2
***************************************************************
if "$table_A2" == "on" {

use "${dir_data}/sd_hh_endline", clear

// 	TABS: 
	tab r1_sd_support_10hhs
	tab r2_sd_support_10hhs
	tab r3_sd_support_10hhs
	tab r3_sd_support_10hhs if sdtreat==0 
	tab r3_sd_support_10hhs if sdtreat==1 
	tab r3_sd_support_10hhs if sdtreat==2 
	
}


***************************************************************
//					Figure A.3
***************************************************************
if "$figure_A3" == "on" {
	
use "${dir_data}/sd_hh_endline", clear
	
// 	DISTRIBUTIONS BY TREATMENT GROUP
	// label for plot
	gen sdlabel = "Control" if sdtreat == 0
	replace sdlabel = "Social Norm Correction" if sdtreat==1
	
	// Set Scheme and Plot
	set scheme plotplain
	distplot r3_sd_support_10hhs if sdtreat != 2, ///
		over(sdlabel) ytitle("Probability <= X-axis variable") ///
		legend(pos(6) cols(2) rows(1))
		
	graph export "${dir_outputs}/figure_A3.png", replace 
	
}


***************************************************************
//					Table A.3
***************************************************************
if "$table_A3" == "on" {

use "${dir_data}/sd_hh_endline", clear
	
// 	REGRESSIONS	
	// table 
	global title "Table A7: Treatment Effects on Perceived Community Support (PCS)"
	// models
	global model "sd1_commsupp sd2_endorse"
	// outcome variables
	global sdvars "sd_support_10hhs sd_support_ge5hh"
	// labels
	label var r3_sd_support_10hhs "Continuous PCS"
	label var r3_sd_support_ge5hh "Indicator if PCS $\ge$ 50\%"
	
	// Reset Table Replace
	local replace replace

// MAIN ANALYSIS
	// Forloop for sdtreat regressions
	foreach yvar in $sdvars {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == . 
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		qui: areg r3_`yvar' ${model} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A3.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			drop r2_yvar*
			
		}

	// new variable
	local yvar "r3_sd_norm_improvement" 	
	label var r3_sd_norm_improvement	"Indicator if PCS Increased"
		
		qui: areg `yvar' ${model} i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum `yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A3.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
}


***************************************************************
//					Table A.4
***************************************************************	
if "$table_A4" == "on" {

use "${dir_data}/sd_hh_endline", clear
			
	// toggle global output for frmttable
	if "$latex" != "on" global output ""
	
	// specify variable
	global sumsdvars c14_sd3 c14_sd4 c14_sd5 c14_sd9 c14_sd10 c14_sd11 c14_sd12 c14_sd13 	
	
	local vars ${sumsdvars}

	local numvars : word count `vars'
	tokenize `vars'
	forvalues i = 1/`numvars'  {
		sum r2_``i'' 
			local r2_N = r(N)	
			local r2_mean = r(mean)
			local r2_sd = r(sd)
		sum r3_``i'' 
			local r3_N = r(N)
			local r3_mean = r(mean)
			local r3_sd = r(sd)
		ttest r2_``i''=r3_``i'' // paired ttest for those surveyed in both rounds
			local N = r(N)
			di "`N'"
			local pval = r(p)
		mat b = (`r2_N',`r2_mean',`r2_sd',`r3_N',`r3_mean',`r3_sd',`pval'\.,.,.,.,.,.,.)
		if `i'==1 {
				mat d = b
			}
			else {
				mat d = d\b  
			}
	}
		
	*mat rownames d = `vars'
	frmttable using "${dir_outputs}/table_A4", $output statmat(d) replace ///
		ctitles("VARIABLES","{\ul Baseline}","","","{\ul Endline}","","","T-test" \ "","N","Mean","SD","N","Mean","SD","p-value") ///
		rtitles("Shop in crowded areas"\"like informal markets (No)"\"Gather with several friends (No)"\""\"Help the elderly avoid close contact with"\"other people including children (Yes)"\"If show symptoms of coronavirus, immediately"\"inform my household and avoid people (Yes)"\"Drink alcohol in bars (No)"\""\"Wear a face mask if showing"\"symptoms of coronavirus (Yes)"\"Instead of meeting in person, call"\"on the phone or send text message (Yes)"\"Allow children to build immunity by playing"\"with children from other households (No)") ///
		multicol(1,2,3;1,5,3) sdec(0,3,3,0,3,3,4)
	
	// restore toggle global output
	if "$latex" != "on" global output "excel"
	
}

	
***************************************************************
//					Table A.5
***************************************************************
if "$table_A5" == "on" {

	// Models
	global model "sd1_commsupp sd2_endorse"

	// Reset Table Replace
	local replace replace

// ATTRITION ANALYSIS:
use "${dir_data}/sd_hh_full", clear

	// Generate attrition outcome
	keep if r2_sample==1 // start with baseline sample
	gen r2r3_attrition = r3_sample==0 if r2_sample==1 
	label var r2r3_attrition "Attrition" 
		
	// Forloop for sdtreat regressions
	foreach yvar in r2r3_attrition {  
		local ylab: variable label `yvar' // Outcome Label
		local ylab "`ylab'"
		
		di "`yvar' ${model}"
	
		areg `yvar' ${model}, a(id_school) robust
		qui: sum `yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			estadd scalar my = r(mean)
			local sdy = r(sd)
			estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A5.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones

			local replace
		}

// BALANCE ANALYSIS
use "${dir_data}/sd_hh_endline", clear

	// outcome variables
	global yvars "r2_sd_pap r2_sd_others r2_sd_self r2_sd_support_10hhs r1_hhincome r1_foodinsecure_yn r1_hhelderly"
	
	// Relabel Column Titles
	label var r2_sd_support_10hhs	"Perceived Social Norm" 
	label var r2_sd_pap 			"Primary SD Indicator" 
	label var r2_sd_others			"Others' Report of SD" 
	label var r2_sd_self			"Self Report of SD"	
	label var r1_hhincome			"Hh Income" 
	label var r1_foodinsecure_yn	"Food Insecurity"	
	label var r1_hhelderly			"Older Adult in Hh" 
	
	// Forloop for sdtreat regressions
	foreach yvar in $yvars {  
		local ylab: variable label `yvar' // Outcome Label
		local ylab "`ylab'"
		
		qui: areg `yvar' ${model}, a(id_school) robust
		qui: sum `yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui estadd scalar my = r(mean)
			local sdy = r(sd)
			qui estadd scalar sdy = r(sd)
			
			// 4 decimals for output
			if "`yvar'"!="r1_hhincome" {
			outreg2 using "${dir_outputs}/table_A5.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			}
			
			// 2 decimals for coefficients and SE, 0 decimals for Control Mean and SD
			if "`yvar'"=="r1_hhincome" {
			outreg2 using "${dir_outputs}/table_A5.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(2) sdec(2) ///
			`replace' // add replace option to first outreg to clear previous ones
			}
			
			local replace
		}		
		}
	

***************************************************************
//					Table A.6
***************************************************************
if "$table_A6" == "on" {

use "${dir_data}/sd_hh_endline", clear

	// models
	global model1 "sd1_commsupp sd2_endorse"
	global model2 "sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl"
	// outcome variables
	global sdvars "sd_pap c25_2"

	// Rename baseline values
	cap rename r1_c25_2 r2_c25_2
	
	// Reset Table Replace
	local replace replace

// MAIN ANALYSIS

// Regressions
	// Forloop for sdtreat regressions
	foreach yvar in $sdvars {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == . 
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		// Main Effects
		qui: logit r3_`yvar' ${model1} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd i.id_school, robust
		margins, dydx(sd1_commsupp sd2_endorse) post
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A6.${file}", $output label ///
			ctitle("`ylab'") ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
		
			local replace
			
		// Heterogenous Effects
		qui: logit r3_`yvar' ${model2} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd i.id_school, robust
		margins, dydx(sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl) post
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)
		
			outreg2 using "${dir_outputs}/table_A6.${file}", $output label ///
			ctitle("`ylab'") ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			drop r2_yvar*
			
		}
}


***************************************************************
//					Table A.7
***************************************************************
if "$table_A7" == "on" {

use "${dir_data}/sd_hh_endline", clear

	// models
	global model1 "sd1_commsupp sd2_endorse"
	global model2 "sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl"
	// outcome variables
	global sdvars "sd_pap c25_2"
	
	// Rename baseline values
	cap rename r1_c25_2 r2_c25_2
	
	// Reset Table Replace
	local replace replace

// MAIN ANALYSIS

// Regressions
	// Forloop for sdtreat regressions
	foreach yvar in $sdvars {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == . 
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		// Main Effects
		qui: probit r3_`yvar' ${model1} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd i.id_school, robust
		margins, dydx(sd1_commsupp sd2_endorse) post
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A7.${file}", $output label ///
			ctitle("`ylab'") ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
		
			local replace
			
		// Heterogenous Effects
		qui: probit r3_`yvar' ${model2} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd i.id_school, robust
		margins, dydx(sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl) post
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)
		
			outreg2 using "${dir_outputs}/table_A7.${file}", $output label ///
			ctitle("`ylab'") ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			drop r2_yvar*
			
		}	
}


***************************************************************
//					Table A.8
***************************************************************
if "$table_A8" == "on" {

use "${dir_data}/sd_hh_endline", clear
	
// models
	global model1 "sd1_commsupp sd2_endorse"
	global model2 "sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl"
	// outcome variables
	global sdvars "sd_pap"
	
	// Reset Table Replace
	local replace replace

// Regressions
	// Forloop for sdtreat regressions
	foreach yvar in $sdvars {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == . 
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
	// Forloop of models
	foreach m in 1 2 {
	
		// Cluster at School Level
		qui: areg r3_`yvar' ${model`m'} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) vce(cluster id_school)
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A8.${file}", $output label ///
			ctitle("`ylab'","Clustered at Community") ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
		
			local replace

		// Cluster at District Level
		// Cluster at School Level
		qui: areg r3_`yvar' ${model`m'} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) vce(cluster id_district)
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A8.${file}", $output label ///
			ctitle("`ylab'","Clustered at District") ///		
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
		
		} // model
		
		local replace
		drop r2_yvar*
		
		} // sdvars
}


***************************************************************
//					Table A.9
***************************************************************
if "$table_A9" == "on" {

use "${dir_data}/sd_hh_endline", clear

	// models
	global model1 "sd1_commsupp sd2_endorse"
	global model2 "sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl"
	// outcome variables
	global sdvars "sd_pap_alt sd_pap_drop2"
		label var r3_sd_pap_alt "Alternative SD Indicator 1"
		label var r3_sd_pap_drop2 "Alternative SD Indicator 2"
	
	// Reset Table Replace
	local replace replace

// Regressions
	// Forloop for sdtreat regressions
	foreach yvar in $sdvars {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == . 
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		// Main Effects
		qui: areg r3_`yvar' ${model1} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A9.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
		
			local replace
			
		// Heterogenous Effects
		qui: areg r3_`yvar' ${model2} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)
		
			outreg2 using "${dir_outputs}/table_A9.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			drop r2_yvar*
			
		}
}


***************************************************************
//					Table A.10
***************************************************************
if "$table_A10" == "on" {

use "${dir_data}/sd_hh_endline", clear

	// models
	global model1 "sd1_commsupp sd2_endorse"
	global model2 "sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl"
	// outcome variables
	global sdvars "sd_self sd_others"
	
	// Reset Table Replace
	local replace replace

// Regressions
	// Forloop for sdtreat regressions
	foreach yvar in $sdvars {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == . 
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		// Main Effects
		qui: areg r3_`yvar' ${model1} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A10.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
		
			local replace
			
		// Heterogenous Effects
		qui: areg r3_`yvar' ${model2} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)
		
			outreg2 using "${dir_outputs}/table_A10.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			drop r2_yvar*
			
		}
}


***************************************************************
//					Table A.11
***************************************************************
if "$table_A11" == "on" {	
    
use "${dir_data}/sd_hh_endline", clear
		
	// models
	global model1 "sd1_commsupp sd2_endorse sd1_commsupp_r3_cases_dlvl sd2_endorse_r3_cases_dlvl"
	global model2 "sd1_commsupp sd2_endorse sd1_commsupp_r3_top3cases_dlvl sd2_endorse_r3_top3cases_dlvl"
	global model3 "sd1_commsupp sd2_endorse sd1_commsupp_r3_top2cases_dlvl sd2_endorse_r3_top2cases_dlvl"
	global model4 "sd1_commsupp sd2_endorse sd1_commsupp_r3_top1cases_dlvl sd2_endorse_r3_top1cases_dlvl"	
	// outcome variables
	global sdvars "sd_pap"
	// table details
	global title "Table: Treatment Effects on Social Distancing in Top COVID-19 Districts"

// New variables
	// Interactions with levels of cases
	gen sd1_commsupp_r3_cases_dlvl = sd1_commsupp*r3_cases_dlvl 
	gen sd2_endorse_r3_cases_dlvl = sd2_endorse*r3_cases_dlvl

	// National cases per capita
		*9296 cumulative covid-19 cases in Mozambique on October 5 2020 (start of R3): https://coronavirus.jhu.edu/region/mozambique
		*Population of Mozambique, World Bank: 31260000	or 312.6 per 100,000
		*29.73768394 cases per 100,000
	// Generate hicases variables
	sum r3_pccases_dlvl, detail // median obs has pccases of 9.29. median community has pccases of 6.80
	tab r3_pccases_dlvl // median district has pccases of 4.29
	gen r3_top3cases_dlvl = r3_pccases_dlvl>5 // 3 districts with highest cases
	gen r3_top2cases_dlvl = r3_pccases_dlvl>10 // 2 districts with highest cases
	gen r3_top1cases_dlvl = r3_pccases_dlvl>30 // 2 districts with highest cases
	foreach i in 1 2 3 {
	gen sd1_commsupp_r3_top`i'cases_dlvl = sd1_commsupp*r3_top`i'cases_dlvl 
	gen sd2_endorse_r3_top`i'cases_dlvl = sd2_endorse*r3_top`i'cases_dlvl
	}
		
	// Labels
	label var sd1_commsupp_r3_cases_dlvl 	"T1 $\times$ District COVID-19 Case Count"
	label var sd2_endorse_r3_cases_dlvl 	"T2 $\times$ District COVID-19 Case Count"
	label var sd1_commsupp_r3_top3cases_dlvl 	"T1 $\times$ Dummy if Cases Above District Median"
	label var sd2_endorse_r3_top3cases_dlvl 	"T2 $\times$ Dummy if Cases Above District Median"
	label var sd1_commsupp_r3_top2cases_dlvl 	"T1 $\times$ Dummy if Cases Above Sample Median"
	label var sd2_endorse_r3_top2cases_dlvl 	"T2 $\times$ Dummy if Cases Above Sample Median"
	label var sd1_commsupp_r3_top1cases_dlvl 	"T1 $\times$ Dummy if Cases Above National Average"
	label var sd2_endorse_r3_top1cases_dlvl 	"T2 $\times$ Dummy if Cases Above National Average"
		
	// Rename baseline values
	cap rename r1_c25_2 r2_c25_2

	// Reset Table Replace
	local replace replace

// Regressions
	// Forloop for sdtreat regressions
	foreach yvar in $sdvars {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == . 
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		// Heterogenous Effects
		foreach m in 1 2 3 4 {
		areg r3_`yvar' ${model`m'} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)
		
			outreg2 using "${dir_outputs}/table_A11.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp* sd2_endorse*) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			}
			drop r2_yvar*			
		}
		
}


***************************************************************
//					Table A.12
***************************************************************
if "$table_A12" == "on" {	

use "${dir_data}/sd_hh_endline", clear
    
	// models
	global model1 "sd1_commsupp sd2_endorse"
	global model2 "sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl"
	// outcome variables
	global sdvars "sd_pap"
	// table details
	global title "Table: Treatment Effects on Social Distancing, Excluding Chimoio District"
	
	// Rename baseline values
	cap rename r1_c25_2 r2_c25_2
	
	// Reset Table Replace
	local replace replace

// Regressions
	// Forloop for sdtreat regressions
	foreach yvar in $sdvars {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == . 
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		// Main Effects
		qui: areg r3_`yvar' ${model1} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd if id_district != 4, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A12.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
		
			local replace
			
		// Heterogenous Effects
		qui: areg r3_`yvar' ${model2} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd if id_district != 4, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			qui: estadd scalar my = r(mean)
			local sdy = r(sd)
			qui: estadd scalar sdy = r(sd)
		
			outreg2 using "${dir_outputs}/table_A12.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse sd1_commsupp_r3_pccases_dlvl sd2_endorse_r3_pccases_dlvl) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			drop r2_yvar*
			
		}
}

	
***************************************************************
//					Table A.13
***************************************************************
if "$table_A13" == "on" {

use "${dir_data}/sd_hh_endline", clear

	// Reset Table Replace
	local replace replace
	
// MAIN ANALYSIS
	// Model 1: sd1_commsupp sd2_endorse
	foreach yvar in sd_pap sd_self sd_others {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == .
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		qui: areg r3_`yvar' sd1_commsupp sd2_endorse r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			local sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A13.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse sd_pooled) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			drop r2_yvar*
		}

	// Model 2: sd_pooled
	foreach yvar in sd_pap {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == .
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		qui: areg r3_`yvar' sd_pooled r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			local sdy = r(sd)

			outreg2 using "${dir_outputs}/table_A13.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep(sd1_commsupp sd2_endorse sd_pooled) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			drop r2_yvar*
		}
}


***************************************************************
//					Table A.14
***************************************************************
if "$table_A14" == "on" {

use "${dir_data}/sd_hh_endline", clear
    
	// models
	global model "sd1_commsupp sd2_endorse k1_incentive k2_feedback k3_both int_k1_incentive_sd1_commsupp int_k1_incentive_sd2_endorse int_k2_feedback_sd1_commsupp int_k2_feedback_sd2_endorse int_k3_both_sd1_commsupp int_k3_both_sd2_endorse"
	// outcome variables
	global sdvars1 "sd_pap"
	
	// labels
	label var k1_incentive "K1: Incentive"
	label var k2_feedback "K2: Feedback"
	label var k3_both "K3: Incentive \& Feedback"
	label var int_k1_incentive_sd1_commsupp "T1 $\times$ K1"
	label var int_k1_incentive_sd2_endorse "T2 $\times$ K1"
	label var int_k2_feedback_sd1_commsupp "T1 $\times$ K2"
	label var int_k2_feedback_sd2_endorse "T2 $\times$ K2"
	label var int_k3_both_sd1_commsupp "T1 $\times$ K3"
	label var int_k3_both_sd2_endorse "T2 $\times$ K3"
	
	// Reset Table Replace
	local replace replace

// MAIN ANALYSIS
	// Forloop for sdtreat regressions
	foreach yvar in $sdvars1 {  
		local ylab: variable label r3_`yvar' // Outcome Label
		local ylab "`ylab'"
		
		// dummy out missing control variables
		clonevar r2_yvar = r2_`yvar'
		gen r2_yvar_msg = r2_`yvar' == . 
		replace r2_yvar = 0 if r2_yvar_msg == 1
	
		qui: areg r3_`yvar' ${model} r2_yvar r2_yvar_msg i.r2_leader_know_count i.r2_otherhh_know_count_bnd, a(id_school) robust
		qui: sum r3_`yvar' if e(sample) == 1 & sdtreat == 0 
			local my = r(mean)
			estadd scalar my = r(mean)
			local sdy = r(sd)
			estadd scalar sdy = r(sd)
			
			_eststo `yvar'

			outreg2 using "${dir_outputs}/table_A14.${file}", $output label ///
			addstat("Control Mean DV", `my',"Control SD DV",`sdy') keep($model) ///
			nocons bdec(4) sdec(4) adec(4) ///
			`replace' // add replace option to first outreg to clear previous ones
			
			local replace
			drop r2_yvar*	
		}
}